

function documentMgtCtrl($scope, $http) {
  'ngInject';
  // 档案盒数据
  this.documentList = [];

  this.shouldTableShow = false;

  this.loadImage = function(image) {
    return require('../../../assets/images/' + image.src);
  };

  // 判断条件跳转到
  this.toDocumentItemMgt = (innerItem) => {
    
    $state.go('documentItemMgt', {
      id: innerItem.id,
      type: 'detail',
      imgUrl: innerItem.src,
      name: innerItem.checkCategoryName
    });
  }

  // 处理档案盒数据用于展示
  this.getDocumentList4show= () => {
    let step = 0;
    let index = 0;
    let result = [];
    this.documentList.forEach((item) => {
      if (step%5 == 0) {
      result.push([]);
    }
    index = result.length;
    step++;
    result[index-1].push(item);
  });
    return result;
  };

  // 检测keyword变化
  $scope.$watch('documentMgt.keyword', (newVal, oldVal) => {
    if (newVal) {
      this.shouldTableShow = true;
    } else {
      this.shouldTableShow = false;
    }
  });

  $scope.$on('$destroy', () => {
    window.keyword = this.keyword;
  })

  this.keyword = window.keyword;

  // 初始化页面方法
  this.initDocumentMgtView = () => {
    $http.get(`${SERVER_CONTEXT}/api/safeCheck/safe/select/all`).
    then((resp) => {
      let data = resp.data;
      let categoryListCache = [],categoryList = [];
      for(let i=0;i<data.length;i++){
        data[i].checkCategoryName == "内业" && (categoryListCache = data[i].sonsList);
      }
      // 遍历ajax返回数据,获得14个考核项
      for(let i=0; i<categoryListCache.length; i++){
        let categoryItem = categoryListCache[i];
        let checkCategoryName = categoryItem.checkCategoryName;
        switch(checkCategoryName) {
          case "责任落实":
                categoryItem.src = 'book1.png';
                categoryList.push(categoryItem);
                break;
          case "管理制度":
                categoryItem.src = 'book2.png';
                categoryList.push(categoryItem);
                break;
          case "工作策划":
                categoryItem.src = 'book3.png';
                categoryList.push(categoryItem);
                break;
          case "人员管理":
                categoryItem.src = 'book4.png';
                categoryList.push(categoryItem);
                break;
          case "安全活动":
                categoryItem.src = 'book5.png';
                categoryList.push(categoryItem);
                break;
          case "机械设备":
                categoryItem.src = 'book6.png';
                categoryList.push(categoryItem);
                break;
          case "临时用电":
                categoryItem.src = 'book7.png';
                categoryList.push(categoryItem);
                break;
          case "风险预控":
                categoryItem.src = 'book8.png';
                categoryList.push(categoryItem);
                break;
          case "专项方案":
                categoryItem.src = 'book9.png';
                categoryList.push(categoryItem);
                break;
          case "危化消防":
                categoryItem.src = 'book10.png';
                categoryList.push(categoryItem);
                break;
          case "应急管理":
                categoryItem.src = 'book11.png';
                categoryList.push(categoryItem);
                break;
          case "专项经费":
                categoryItem.src = 'book12.png';
                categoryList.push(categoryItem);
                break;
          case "检查评价":
                categoryItem.src = 'book13.png';
                categoryList.push(categoryItem);
                break;
          case "事故管理":
                categoryItem.src = 'book14.png';
                categoryList.push(categoryItem);
                break;
          default:

                break;
        }
      }

      // 考核项数据加入$scope
      this.documentList = categoryList;
      console.log(this.documentList);
      // 将原始数据变化为行展示内容
      this.documentList4show = this.getDocumentList4show();
    });
  }
  // 初始化页面
  this.initDocumentMgtView();
}

export default documentMgtCtrl;